package com.school.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.school.mapper.AccountMapper;
import com.school.pojo.Account;
import com.school.pojo.Student;
import com.school.pojo.Teacher;
import com.school.service.AccountService;

@Service
@Transactional
public class AccountServiceImpl implements AccountService {

	@Autowired
	private AccountMapper accountMapper;

	@Override
	public List<Account> findAll() {
		return accountMapper.findAll();
	}

	@Override
	public Account findByUsernameAndPassword(Account account) {
		Account account2 = accountMapper.findByUsernameAndPassword(account);

		return account2;
	}

	@Override
	public int add(Teacher teacher) {

		Account account = accountMapper.findByName(teacher.getUsername());

		if (account == null) {
			return accountMapper.add(teacher);
		}
		return 0;
	}

	@Override
	public Account findById(Integer a_id) {

		return accountMapper.findById(a_id);
	}

	@Override
	public int edit(Teacher t) {
		// TODO Auto-generated method stub
		return accountMapper.edit(t);
	}

	@Override
	public int delbatch(int[] aid) {
		return accountMapper.delbatch(aid);
	}

	@Override
	public int add(Student student) {

		Account account = accountMapper.findByName(student.getUsername());

		if (account == null) {
			return accountMapper.addz(student);
		}

		return 0;

	}

	@Override
	public int edit(Student t) {
		System.out.println("snxzk"+t);
		return accountMapper.edits(t);
	}

}
